# @Time : 2020/7/22 9:53
# @Author : Fioman 
# @Phone : 13149920693


"""
先扫描分析找到所有的id号.
"""



def find_all_board_index():
    idAdded = []
    with open("debug.txt",encoding='utf-8') as f:
        while True:
            line = f.readline()
            if len(line) <= 0:
                break
            if "取出之后的" in line:
                idFinded = line.split("-")[3].split(" ")[1]
                if idFinded not in idAdded:
                    idAdded.append(idFinded)

    return idAdded


def find_all_data_by_index(indexFinded):
    if len(indexFinded) <= 0:
        return None
    with open("debug.txt",encoding='utf-8') as f:
        strFinded = ""
        while True:
            line = f.readline()
            if len(line) <= 0:
                break
            if indexFinded not in line:
                continue
            if indexFinded not in strFinded:
                strFinded += indexFinded + "  "
            if '识别的切线结果' in line:
                firstBoard = line[:-1].split(",")[-4][1:]
                secondBoard = str(round(float(line[:-1].split(",")[-3][1:]) - float(firstBoard),2))
                topMid = line[:-1].split(",")[-2]
                bottomMid = line[:-1].split(",")[-1][:-1]
                if firstBoard not in strFinded and secondBoard not in strFinded:
                    strFinded += (firstBoard + "  " + secondBoard + "  " + topMid + "  " + bottomMid + "  ")

            if "大铡刀起点验证:验证" in line:
                start = line.index("(")
                end = line.index(")")
                firstCheck = line[start:end+1]
                if firstCheck not in strFinded:
                    strFinded += (firstCheck + "  ")

            if "第一块偏:" in line:
                index1 = line.index("前角")
                index2 = line.index("后角")
                index3 = line.index("总偏差")
                strFinded += line[index1+3:index2-1] + "  "
                strFinded += line[index2+3:index3-1] + "  "

                lineFinded = line.split(":")[7:10]
                for data in lineFinded:
                    strFinded += data.split(",")[0] + "  "
            else:
                continue
            return strFinded






if __name__ == '__main__':
    # 1.找到所有的id号.
    indexFinded = find_all_board_index()
    dataShow = []
    # 2.根据id号找到要显示的数据
    for index in indexFinded:
        dataFinded = find_all_data_by_index(index)
        dataShow.append(dataFinded)
    with open("res.txt","w") as f:
        f.write("id_号    识别1    识别2    1Mid    3Mid    首检    前角    后角    总偏    第一块    第二块\n")
        for data in dataShow:
            f.write(data)
            f.write("\n")


